public class Word
{
  private String _st;

  /***
  /* s1 - first string of compare
  /* s2 - seconds string
  /* return: 1: if s1>s2 , return -1  if s1<s2 , returns 0 if two strings equals
   */
  
  // Constructor
  public Word (String st)
  {
	  _st = st;
  }
  
  

  /***
   *  Lexicographicly  Compares String s1 with String s2 , 
   * @param s1
   * @param s2
   * @return 1 if s1 is larger, -1 if s2 is larger 
   * 
   */
  
    public int myCompare (String s1,String s2)
  {

	  //  measure the length of each string
	  int lenS1 = s1.length();
	  int lenS2 = s2.length();
	  
	  
	  // iterate over the first string
	  for (int  i=0;i<lenS1; i++)
	  {

		  //check if s2 is out of bounds -> then s1 has more chars
		if( i>=lenS2 )
		{
			return 1;
		}
		
			
		  if(s1.charAt(i)>s2.charAt(i))
		  {
			  return 1;
		  }
		  if (s1.charAt(i)<s2.charAt(i))
		  {
			  return -1;
		  }
		  //if the  two chars at the i index are equal
  
		  
	  }
	 
	  //if we reach here then s1 is part of s2 (s2 has more chars)	 or s1 is equal to s2 

	  //if they length are equal then 
	  if(lenS1==lenS2)
		  return 0;
	  else
		  return -1;
	  
  }
  
  // Auxiliray helper function 
  //Look for the the first occurrence of char inside a string
  private int myIndexOf(String str,char c,int in)  
  {
	  //measure the length of _st
	  int ln = str.length();

	  // iterate over the _str until the  first occurrence of c is found
	  for (int i=in;i<ln;i++ )
	  {
		  if(str.charAt(i)==c)
		  {
			  return i;
		  }
	  
	  }
	  // if we get here there is no such char at the String
	  return -1;
  }
  
  
  public int myIndexOf(char c)
  {

	  // look for char c starting from the beginning
	  return  myIndexOf(_st,c,0);
	  
  }
  
  
  // look for the given char starting from the index
  public int myIndexOf(char c,int ind)
  {
	  int ln = _st.length();
	  
	  //avoid out of bound index.
	  if (ind>=ln)
		  return -1;
	  
	// look for char c starting from the index	  
	  return myIndexOf(_st,c,ind);
  }
  
  /**
   * Check if the given string contained within _str , starting from the  index in
   * @param st
   * @param in
   * @return
   */
  private boolean strExistsAt (String st , int in)
  {

	  //avoid out of range  error
	  if( st.length() > _st.length() - in)
	  {
		return false;  
	  }
	  
	  
	  // check if the char combination is exact 
	  for (int i=0; i<st.length();i++)
	  {
		  //position at the _str should be increased by 1
		  		  
		  //check if the chars are equal
		  if ( _st.charAt(in) != st.charAt(i))
			  return false;

		  in++;		  
		  
	  }
	  
	  return true;

	  
	  
  }

  
  
  //look for the given String 
  public int myIndexOf(String str)
  {
	  //iterate over the string and make sure its chars are exists
	   char firstletr = str.charAt(0);
	  
	  
	   
	   // iterate over the _st and look for the first letter of our string
	  for (int i=0;i<_st.length();i++)
	  {
		  if(_st.charAt(i) == firstletr )
		  {
			  
			  //check the exact combination exist at the index
			  if ( strExistsAt (str,i) )
			  {
				  return 1;
			  }
		  }
		  
	  }
	  
	  	  
	  return -1;
  }
  
// look for the given string starting from the index
  public int myIndexOf(String str, int ind)
  {
	  //iterate over the string and make sure its chars are exists
	  int len = str.length();
	  
	  // use the function we defined earlier
	  //look for the first char index at the _str
	  int pos = myIndexOf( str.charAt(0) , ind);
	  
	  
	  if(pos==-1)
		  return -1;
	  
	  
	  
	  //  str.charAt(i)
	  //start from the second char at the str
	  for (int i=1; i<len;i++)
	  {
		  //position at the _str should be increased by 1
		  pos++;
		  
		  
		  //check if the next chars are equal
		  int posnext =  myIndexOf( str.charAt(i) , pos);

		  if ( posnext == -1 )
			  return -1;

		  if(posnext!=pos)
			  return -1;
		  
		  
	  }
	  
	  return 1;
  }
  
  
  // cut the _str string starting from i
  public String mySubstring(int i)
  {
	  
	  //make sure that we are not out of bound
	  if(i >= _st.length() )
	   return "";
	  
	  //declare empty string
	  String str="";

	  //System.out.println(_st.length());
	  
	  
	  //iterate over the string chars starting from the index j
	  for (int j=i;j<_st.length();j++)
	  {
		  str = str + _st.charAt(j);
	  }
	  
	  return str;
  }

  // cut the _str from index i until index j
  public String mySubstring(int i,int j)
  {
	
	  //Avoid out of band 
	  if (i >= _st.length() || j>=_st.length() || i>j )
	  {
		  return "";
				  
	  }
	  
	  
	  // str will hold the final String
	  String str="";
	  
	  
	  // iterate the _str starting from i untill we reach j
	  for (int t=i;t<=j;t++)
	  {
		  str= str + _st.charAt(t);
	  }
	  
	  
	  return str;
	  
  }
  
}